package com.yueguanjia.pay;

import android.content.Intent;
import android.webkit.WebView;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;

/**
 * Created by Milo on 16/7/5.
 */
public class BankPay extends CordovaPlugin {

    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
        System.out.println("initialize is executed!");
    }

    @Override
    protected void pluginInitialize() {
        super.pluginInitialize();
        System.out.println("pluginInitialize is executed!");
    }

    @Override
    public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {

        if (action.equals("cmb")) {

            cordova.getThreadPool().execute(new Runnable() {
                @Override
                public void run() {

                    try {
                        cmb(callbackContext);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }
            });

        }

        return true;

    }

    public void cmb(CallbackContext callbackContext) throws JSONException {

        System.out.println("test is execute!");

        Intent intent = new Intent();
        intent.setClass(cordova.getActivity(), BankPayActivity.class);
        cordova.startActivityForResult(this, intent, 1);

    }

}